import request from "@/utils/request";
import requestMock from "@/utils/request-mock";
import type { UserInfo, LoginResponse } from "./models";
import type { RouteRecordRaw } from "vue-router";

enum Api {
  getUserInfoUrl = `/admin/acl/index/info`,
  loginUrl = `/admin/acl/index/login`,
  logoutUrl = `/admin/acl/index/logout`,

  getRoutesUrl = `/permission/routes`,
}

/**
 * 获取用户信息
 * @returns UserInfo
 */
export const getUserInfoApi = () => {
  return request.get<any, UserInfo>(Api.getUserInfoUrl);
};

/**
 * 登录
 * @param username 用户名
 * @param password 密码
 * @returns LoginResponse
 */
export const loginApi = (username: string, password: string) => {
  return request.post<any, LoginResponse>(Api.loginUrl, { username, password });
};

/**
 * 退出登录
 * @returns null
 */
export const logoutApi = () => {
  return request.post<any, null>(Api.logoutUrl);
};

/**
 * 获取后台定义路由权限列表
 * @returns RouteRecordRaw[]
 */
export const getRoutesApi = () => {
  return requestMock.get<any, RouteRecordRaw[]>(Api.getRoutesUrl);
};
